package com.heima.file.config;

import com.heima.file.pojo.MinIOConfigProperties;
import com.heima.file.service.FileStorageService;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@EnableConfigurationProperties(MinIOConfigProperties.class)
//当引入FileStorageService接口时
@ConditionalOnClass(FileStorageService.class)
public class MinIOConfig {

    @Autowired
    private MinIOConfigProperties minIOConfigProperties;

    @Bean
    public MinioClient buildMinioClient(){
        return MinioClient.builder().
                credentials(minIOConfigProperties.getAccesskey(),
                        minIOConfigProperties.getSecretkey()).
                endpoint(minIOConfigProperties.getEndpoint()).build();
    }
}
